class StringUtil {
  static trimSpace(str: string) {
    return str.replace(/\s+/g, "");
  }
}
// 方法连拦截器
function MethodInterceptor<T>(param: any) {
  return function (
    targetClassPrototype: any,
    methodname: string,
    dataProps: TypedPropertyDescriptor<T>
  ) {
    const targetMethod = dataProps!.value;
    (dataProps as any).value = function (...args: any[]) {
      args = args.map((arg) => {
        if (typeof arg === "string") return StringUtil.trimSpace(arg);
        return arg;
      });

      console.log("前置拦截");
      console.log("args:", args);
      (targetMethod as any).apply(this.args);
      console.log("后置拦截");
    };
  };
}

class RoleService {
  public roleName: string = "管理员";
  constructor() {}

  get DistribRole1_() {
    return this.DistribRole1();
  }

  // @MethodInterceptor("DistribRoles方法")
  DistribRole1() {
    // 分配角色(元方法)
    console.log("分配角色");
  }

  @MethodInterceptor("DistribRoles方法")
  DistribRoles(username: string, isValid: boolean) {
    // 分配角色
    console.log("分配角色");
  }
}

let role = new RoleService();
role.DistribRoles("abs", true);

export {};
